﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.UC
{
    public partial class SummaryGioHangCtrl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Dictionary<long, SAN_PHAM> Cart = Session["Cart"] as Dictionary<long, SAN_PHAM>;
                long? tt = 0;
                string tien = string.Empty;
                foreach (KeyValuePair<long, SAN_PHAM> item in Cart)
                {
                    if (item.Value.NgayBatDau <= DateTime.Now && item.Value.NgayKetThuc >= DateTime.Now)
                    {
                        long? thanhtien = (item.Value.DonGia - ((item.Value.DonGia * item.Value.GiamGia) / 100)) * item.Value.SoLuong;
                        tt += thanhtien;
                    }
                    else
                    {
                        tt += item.Value.DonGia * item.Value.SoLuong;
                    }
                }

                string tongtien = String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                 "{0:0,0}", tt) + " đ";
                string vat = String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                             "{0:0,0}", (tt * 10) / 100) + " đ";
                string ttt = String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                             "{0:0,0}", tt + (tt * 10 / 100)) + " đ";

                sTongTien.InnerHtml = tongtien;
                sVAT.InnerHtml = vat;
                sThanhTien.InnerHtml = ttt;
            }
        }
    }
}